// m4fx parse
#include "f4f.h"

// F4F file specification (http://opensource.adobe.com/svn/opensource/osmf/trunk/framework/OSMF/org/osmf/net/httpstreaming/f4f/)
// http://opensource.adobe.com/svn/opensource/osmf/trunk/framework/OSMF/org/osmf/net/httpstreaming/f4f/F4FConstants.as

int main(int argc, char* argv[])
{
	PF4F_FORMAT p = 0;
	F4F_PACKET  pkt;
	int index = 0;

	if (argc < 2)
		return -1;

	p = (PF4F_FORMAT) f4f_open_file(argv[1], 0);
	if (p)
	{
		// read mdat header
		f4f_read_mdat(p);

		// initialize packet
		f4f_init_packet(&pkt);

		// read packet
		while (f4f_get_next_frame(p, &pkt) > 0)
		{
			printf("%d: pkt.size : %d,", index, pkt.size);
			printf("pkt.dts : %lld,", pkt.dts);
			printf("pkt.pts : %lld\r\n", pkt.pts);
			printf("pkt.data : ");
			print_hex(pkt.data, pkt.size > 16 ? 16 : pkt.size);
			printf("\r\n");
			index++;
		}

		f4f_release_packet(&pkt);
		printf("\r\n");	
		f4f_close(p);
	}
	return 0;
}